<template>
  <div style="height:100%" class="consume-content">
    <div class="top">
      <van-nav-bar left-arrow @click-left="goBack"/>
      <div class="title">Consume</div>
    </div>
    <div class="send-list mt20">
      <van-list v-model="loading" :finished="finished" :immediate-check="false" finished-text="" @load="loadData">
        <div v-for="item in list" :key="item.id" @click="checkDetail(item)" class="consume-out" style="">
          <div class="goods-item flex">
            <div class="goods-image flex-none">
              <div class="jingxuan">
                <van-image :src="item.showImg" fit="cover">
                  <template v-slot:loading>
                    <van-loading type="spinner" size="20" />
                  </template>
                </van-image>
              </div>
            </div>
            <div class="goods-info flex-auto width0">
              <div>
                <div class="goods-title text-ellipsis-2">{{ JSON.parse(item.goodsInfo).name }}</div>
                <div class="flex flex-justify-content-between" style="margin-top: 10px">
                  <div class="goods-price">Visualizações：{{ JSON.parse(item.goodsInfo).views }}</div>
                </div>
              </div>
              <div class="flex flex-justify-content-between" style="margin-top: 10px">
                <div class="goods-title">{{ JSON.parse(item.goodsInfo).categoryName }}</div>
              </div>
              
            </div>
          </div>
          <div class="user-info">
            <div class="user-info-item">
            <van-icon name="aim"></van-icon>
              <span class="mr10 ml5">Time：{{ item.payTime }}</span>
            </div>
            <div class="user-info-item">
              <van-icon name="wap-home-o"></van-icon>
              <span class="mr10 ml5">ID：{{ item.id }}</span>
            </div>
            <div class="user-info-item">
              <van-icon name="bill-o"></van-icon>
              <span class="mr10 ml5">{{ item.payMoney | num2Money }} KZ</span>
            </div>
          </div>
        </div>
      </van-list>
    </div>
    <!-- 对话框 -->
    <van-overlay :show="show" @click="show = false">
      <div class="wrapper" @click.stop>
         <ConsumeDetail @cancel='cancel' :id="id"></ConsumeDetail>
      </div>
    </van-overlay>
  </div>
</template>
<script>
import Api from '@/api';
import { Domain } from '@/constants';
import ConsumeDetail from "@/components/consume/ConsumeDetail"
export default {
  name: 'SendList',
  components: {ConsumeDetail},
  data() {
    return {
      domain: Domain,
      addDialogVisible: false,
      params: {
        pageSize:50,
        pageNo: 0,
      },
      total: 0,
      list: [],
      loading: false,
      finished: false,
      show:false,
      id:"",
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    loadData() {
      console.log(this.params.pageNo)
      this.params.pageNo++;
      console.log(this.params.pageNo)
      Api.payOrderList(this.params).then((res) => {
        const newList = res.rows.map((item) => {
          const img = JSON.parse(item.goodsInfo).imgList ? JSON.parse(JSON.parse(item.goodsInfo).imgList)[0] : '';
          return Object.assign(item, { showImg: Domain + img });
        });
        this.list = this.list.concat(newList);
        if (newList.length < this.params.pageSize) {
          this.loading = false;
          this.finished = true;
        }
        console.log(this.list)
        console.log(this.finished)
      })
    },
    goBack(){
      this.$router.go(-1)
    },
    cancel(val){
      this.show = val
    },
    checkDetail(val){
      this.id = val.id
      this.show = true
    }
    
  },
};
</script>
<style lang="scss" scoped>
.consume-content{
  height: 100%;
  display: flex;
  flex-direction: column;
}
.send-list{
  flex: 1;
  padding: 12px;
  padding-top: 0;
  ::v-deep.van-list{
    height: 100%;
    padding-bottom: 10px;
  }
}

::v-deep.van-nav-bar{
  background-color: #fff;
  padding: 0 10px;
  .van-nav-bar__left{
    padding: 0;
    .van-icon{
      font-size: 26px;
      color: #000000;
    }
  }
}
.title {
  font-size: 20px;
  line-height: 50px;
  padding-left: 16px;
  font-weight: bold;
  background: #fff;
}
.goods-item {
  padding: 10px 10px 0px 8px;
  margin-bottom: 10px;
  box-sizing: border-box;
  overflow: hidden;
  .goods-image {
    margin-right: 8px;
    width: 50%;
    height: 120px;
    
    .jingxuan {
      position: relative;
      width: 100%;
      height: 100%;
      border-radius: 6px;
      overflow: hidden;
      .van-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
        min-height: 140px;
      }
    }
  }
  .goods-info{
    
  }
  .goods-title {
    color: #666;
    font-size: 14px;
  }
  .goods-desc {
    font-size: 12px;
    color: #666;
    margin: 8px 0;
    overflow: hidden;
    // max-height: 60px;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .goods-price {
    color: #333;
    font-size: 15px;
    font-weight: bold;
  }
  
}
.user-info {
  border-top: 1px solid #ebedf0;
    font-size: 12px;
    color: #666;
    display: flex;
    flex-direction: column;
    padding: 10px;
    padding-top: 0;
    
    
    .user-info-item{
      display: flex;
      align-items: center;
      margin-top: 5px;
    }
  }
.consume-out{
  background-color: #fff;
  margin-bottom:10px;
  border-radius: 6px;
}
.van-overlay{
  height: 100%;
  background-color: #fff;
}
</style>
